angular.module('starter.user.service', [])

  .factory('$$UserEditService', function($rootScope, $$HttpService) {
    console.info("factory----------$$UserEditService");
    return {
      // 编辑用户个人信息
      updateUser: function(userMsg) {
        // var data = {
        //   memberId: $rootScope.userData.id,
        //   avatar: userMsg.avatar,
        //   nickname: userMsg.nickname,
        //   token: $rootScope.userData.token,
        // };
        // if (userMsg.password != "") {
        //   data.password = userMsg.password;
        // }
        // return $http.post($rootScope.config.apiHost + "api/v1/member/memberAmend.api", $$SignService.sign(data));
        var req = {
          headPic: userMsg.avatar,
          signature: userMsg.signature,
        };
        if (userMsg.password != "") {
          req.password = userMsg.password;
        }
        console.log(req);
        return $$HttpService.timepost("api/user/edit", req);
      }
    };
  })


  .factory('$$UserAuthService', function($rootScope, $$HttpService) {
    console.info("factory----------$$UserAuthService");
    return {
      // 获取用户认证状态
      authenticationState: function() {
        return $$HttpService.timeget("api/user/authenticationState", {});
      },
      // 实名认证
      authRealname: function(data) {
        var req = {
          realName: data.realName,
          idNO: data.idNO,
          idBackPic: data.idBackPic,
          idObversePic: data.idObversePic,
          sex: data.sex,
        };
        console.log(req);
        return $$HttpService.timepost("api/user/authentication", req);
      },
      // 向导认证
      authguide: function(data) {
        var req = {
          contactPhone: $rootScope.userData.telephone, //"string"
          introduce: data.introduce, //"string"
          job: data.job, //0
          hotId: data.hotId,
          displayPic: data.displayPic,
          lifePic: data.lifePic, //"string"
          region: data.region, //0
          serviceCity: data.serviceCityName, //0
          serviceContent: data.serviceContent, //"string"
          servicePrice: parseInt(data.servicePrice * 100), //double
          serviceRoute: data.serviceRoute, //"string"
          tourGuideCertificationPic: data.tourGuideCertificationPic, //"string"
          weChat: data.weChat //"string
        };

        // var req = {
        //   contactPhone: "13388768745", //"string"
        //   introduce: "introduceintroduceintroduceintroduce", //"string"
        //   job: 2, //0
        //   displayPic: "tx.png",
        //   lifePic: "tx.png", //"string"
        //   hotId: "1,3",
        //   region: "werwe", //0
        //   serviceCity: "wwr", //0
        //   serviceContent: "string", //"string"
        //   servicePrice: parseInt(100.00 * 100), //double
        //   serviceRoute: "哈哈#呵呵#吉吉",       //"string"
        //   tourGuideCertificationPic: "tx.png",  //"string"
        //   weChat: "weChatno" //"string
        // };


        return $$HttpService.timepost("api/guide/authentication", req);
      }
    };
  })

  // 用户订单相关
  .factory('$$UserOrderService', function($rootScope, $$HttpService) {
    console.info("factory----------$$UserAuthService");
    return {

      // 获取订单id,用于生成订单
      getOrderId: function() {
        return $$HttpService.timeget("api/order/getOrderId", {});
      },

      // 用户预约向导
      orderGuide: function(guideId, orderId, formData) {
        var req = {
          contactPhone: $rootScope.userData.telephone, // "string"
          id: orderId,
          guideId: guideId,
          price: formData.price, // 0
          person: formData.person, // 0
          remarks: formData.remarks,
          realName: $rootScope.userData.userName, // "string"
          travelStartDate: formData.travelStartDate.format('yyyy-MM-dd h:m') + ":0", // "string"
          travelEndDate: formData.travelEndDate + ":0", // "string"
        };
        console.log(req);

        return $$HttpService.timepost("api/order/appointment", req);
      },
      // 获取用户的订单列表
      getUserOrders: function() {
        return $$HttpService.timeget("api/order/getUserOrders", {});
      },
      // 获取向导的订单列表
      getGuideOrders: function() {
        return $$HttpService.timeget("api/order/getGuideOrders", {});
      },

      // 改变订单状态 包括于以下业务操作
      // 向导确认预约
      // 游客支付订单
      // 用户确认完成订单
      changeOrderState: function(orderId, state) {
        var req = {
          orderId: orderId,
          state: state
        };
        return $$HttpService.timepost("api/order", req);
      },
      // 向导取消预约
      guideCancelOrder: function(orderId, state) {
        var req = {
          orderId: orderId,
          state: state
        };
        return $$HttpService.timepost("api/order/cancelOrder", req);
      },
      // 用户取消预约
      userCancelOrder: function(orderId, state) {
        var req = {
          orderId: orderId,
          state: state
        };
        return $$HttpService.timepost("api/order/cancelOrder", req);
      },
      // 删除订单
      deleteOrder: function(orderId, state) {
        var req = {
          orderId: orderId,
          state: state
        };
        return $$HttpService.timepost("api/order/deleteOrder", req);
      },

      // 用户评价订单 增加评价
      orderCommont: function(orderId, formData) {
        var req = {
          comment: formData.comment,
          orderId: orderId,
          pic: "tx.png",
          jobMoralityGrade: formData.jobMoralityGrade,
          serviceGrade: formData.serviceGrade,
          speakGrade: formData.speakGrade,
          type: formData.type,
        };
        return $$HttpService.timepost("api/eveluate", req);
      },


      // 用户评价订单 增加评价
      orderCompaint: function(orderId, formData) {
        var req = {
          content: formData.content,
          orderId: orderId,
          pic: formData.pic,
          type: formData.type,
        };
        return $$HttpService.timepost("api/user/complain", req);
      },


    };
  })


  .factory('$$UserFriendService', function($$HttpService) {
    console.info("factory----------$$UserAuthService");
    return {

      // 获取粉丝列表
      getfriendfanslist: function(pageNum, pageSize) {
        var req = {
          pageNum: pageNum,
          pageSize: pageSize,
          type: 1 //获取类型 1粉丝2,关注
        };
        return $$HttpService.timeget("api/friend/list", req);
      },

      // 获取关注列表
      getfriendattentionlist: function(pageNum, pageSize) {
        var req = {
          pageNum: pageNum,
          pageSize: pageSize,
          type: 2 //获取类型 1粉丝2,关注
        };
        return $$HttpService.timeget("api/friend/list", req);
      },

    };
  })


  .factory('$$UserMoneyService', function($$HttpService) {
    console.info("factory----------$$UserAuthService");
    return {
      // 钱包信息
      getusermoneymsg: function(data) {
        return $$HttpService.timeget("api/user/wallet", {});
      },

      // 账单信息
      getuserbillmsg: function(pageNum,pageSize) {
        var req = {
          pageNum:pageNum,
          pageSize:pageSize,
          // createTime:createTime,
          // type:type
        };
        return $$HttpService.timeget("api/user/bill", req);
      },

      // 用户充值（微信和支付宝） 1 微信 2支付宝
      userAddMoney: function(formData) {
        var req = {
          money: formData.money * 100,
          type: formData.paytype
        };
        return $$HttpService.timepost("api/user/preRecharge", req);
      },

      // 用户提现 type 1 支出(预约) 2 收益 3 提现 4 充值
      usergetCash: function(data) {
        var req = {
          money: parseInt(data.money*100),
          userName: data.userName,
          accoutNO: data.accoutNO,
          bank:data.bank,
          type: data.type
        };
        return $$HttpService.timepost("api/user/cash", req);
      }

    };
  })


;
